# -*- coding: utf-8 -*-
"""
------------------------------------------------------------------------------
    File Name:  pandas_demo
    Author   :  wanwei1029
    Date     :  2018-10-16
    Desc     :
------------------------------------------------------------------------------
"""
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt


def series_demo():
    """
    Series相当于是一维数组，显示一条线，也就是一条指标。
    生成Series对象，可以直接指定data和index,比如：pd.Series(data, index)
    也可以通过dict来生成，此时key为index,value为data,series = pd.Series(dict_obj)
    :return:
    """
    data = np.random.rand(10)
    # index = range(1, 11)
    index = list("abcdefghij")
    print(data)
    print(index)
    dict_obj = {"01": 1, "02": 5, "03": 2, "04": 4, "05": 1, "06": 7, "07": 5, "08": 1}
    plt.figure(1)
    series1 = pd.Series(data, index)
    series1.plot()
    plt.figure(2)
    # plt.show()
    series = pd.Series(dict_obj)
    series.plot()
    plt.show()


def dataframe():
    """
    DataFrame相当于多个Series，常用dict方式创建
    """
    dict_obj = dict()
    dict_obj["2018-10-16"] = np.random.randint(1000, size=10)
    dict_obj["2018-10-17"] = np.random.randint(1000, size=10)
    dict_obj["2018-10-18"] = np.random.randint(1000, size=10)
    dict_obj["2018-10-19"] = np.random.randint(1000, size=10)
    index = list("abcdefghij")
    df = pd.DataFrame(dict_obj, index)
    df.plot()
    plt.show()


def demo():
    """
    """
    df = pd.DataFrame(np.random.randn(10, 4), index=pd.date_range('2018/12/18',
                                                                  periods=10), columns=list('ABCD'))
    df.plot()
    plt.show()
    print("done!")


if __name__ == '__main__':
    test_method = "series_demo"
    if test_method == "demo":
        demo()
    elif test_method == "series_demo":
        series_demo()
    elif test_method == "dataframe":
        dataframe()
